package lovoStudy_9_11;

import java.util.Scanner;

/**
 * Created with Intellij IDEA
 * Description:
 *
 * @ return:
 * @ author:zxl
 */
public class Test {

    public static void main(String[] args) {

//        change();
//        change2();
        formatCurtency();
    }
/**
 *驼峰转蛇形
 * */
    public static void change(){
        String camelPattern = "[A-Z][a-z]{1,}[A-Z][a-z]{1,}";
        System.out.println("请输入驼峰命名法的单词: ");
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        int index = 0;
        if (str.matches(camelPattern)){
            char[] chars = str.toCharArray();
            for (int i = 0 ; i < chars.length;i++){
                if (chars[i] >= 65 && chars[i] <= 90){
                chars[i] += 32;
                index++;
                }
                if (index == 2){
                    index = i;
                    break;
                }
            }
//a-97  z-122  A-65  Z-90
            String newStr = String.valueOf(chars);
            String newStr2 = newStr.substring(0,index);
            String newStr3 = "_" + newStr.substring(index);

            System.out.println(newStr2 + newStr3);
        }else {
            System.out.println("输入的不是驼峰命名法单词");
        }

    }
/**
 * 转换蛇形转驼峰
 * */
    public static void change2(){
        String camelPattern = "[a-z]{1,}[_][a-z]{1,}";
        System.out.println("请输入蛇形命名法的单词: ");
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        if (str.matches(camelPattern)){
            String newStr = str.substring(0,str.indexOf("_"));
            String newStr2 = str.substring(str.indexOf("_") + 1);
            char[] chars = newStr2.toCharArray();
            chars[0] -= 32;
            newStr2 = String.valueOf(chars);
            System.out.println(newStr + newStr2);
        }else {
            System.out.println("输入的不是蛇形命名法单词");
            return;
        }
    }
/**
 * 转换千位
 *
 * */
    public static void formatCurtency(){
        System.out.println("请输入货币数字: ");
        Scanner scanner = new Scanner(System.in);
        String input = scanner.next();
        String pattern = "\\d{1,}[.]\\d{1,}";

        if (input.matches(pattern)){
//        StringBuffer stringBuffer = new StringBuffer(input);
        input.indexOf(".");
//        System.out.println(input.indexOf("."));
        String str = input.substring(0,input.indexOf("."));
        String str2 = input.substring(input.indexOf("."));
//        System.out.println(str2);
        StringBuffer stringBuffer = new StringBuffer(str);
        stringBuffer.reverse();
        str = stringBuffer.toString();
        char [] chars = str.toCharArray();
        for (int i = 0; i < chars.length ; i++ ){
            if (i % 3 == 0 && i != 0){
                stringBuffer.insert(i,",");
            }
        }
        stringBuffer.reverse().append(str2);
        System.out.println("输出为: " + stringBuffer);
        }else {
            System.out.println("输入有误");
        }
    }



}
